package com.ansion.commonchat.contact.bean;

import androidx.annotation.Keep;

import com.ansion.adapter.IAdapterData;
import com.ansion.basedb.dao.model.UserModel;
import com.ansion.commonchat.contact.utils.HelperFunc;

import java.util.Objects;

@Keep
public class ContactBaseBean implements IAdapterData {

    private String uniqueTag;//唯一标识
    public UserModel model;
    public boolean isBlock = false;
    protected String diffContent;

    public ContactBaseBean() {

    }

    public ContactBaseBean(String uniqueTag) {
        this.uniqueTag = uniqueTag;
    }

    public ContactBaseBean(UserModel model, boolean isBlock) {
        this.model = model;
        this.isBlock = isBlock;
        setUniqueTag(model != null ? String.valueOf(type + model.getUserId()) : "contact data");
        diffContent = model != null ? String.valueOf(model.getUserId()) : "contact data";
    }

    @Override
    public int getType() {
        return type;
    }

    public int type;


    public String getIndex() {
        String ret = null;
        if (model == null) {
            return null;
        }
        ret = HelperFunc.getAlpha(model.getNameForSort());
        if (ret == null) {
            ret = "";
        }
        return ret;
    }

    public String getSortKey() {
        String ret = null;
        if (model == null) {
            return null;
        }
        ret = model.getSortAlpha();
        return ret;
    }

    public String getIndexDisplay() {
        String ret = getIndex();
        if (ret == null) {
            return "#";
        }

        if (ret.trim().length() == 0) {
            return "#";
        }

        return ret.trim().charAt(0) + "";
    }

    public UserModel getUserModel() {
        return model;
    }

    public void setUniqueTag(String uniqueTag) {
        this.uniqueTag = uniqueTag;
    }

    public String getUniqueTag() {
        return uniqueTag;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof ContactBaseBean)) {
            return false;
        }
        ContactBaseBean that = (ContactBaseBean) o;
        return type == that.type && diffContent.equals(that.diffContent);
    }

    @Override
    public int hashCode() {
        return Objects.hash(diffContent, type);
    }
}
